<?php

namespace App\Http\Controllers\UI;

use App\Miya\Models\Area;
use App\Miya\Models\DerivativeKeyword;
use App\Miya\Models\Keyword;
use Diglactic\Breadcrumbs\Breadcrumbs;

class IndexController extends CommonController
{
    protected $data;

    public function __construct()
    {
        parent::__construct();
        $this->data['area'] = new Area(); //地区兜底
        $this->data['title'] = config('web.title');
        $this->data['keywords'] = miya('keyword')->list()->join(',');
        $this->data['description'] = config('web.description');
        $this->data['breadcrumb'] = Breadcrumbs::render('index');
    }

    /**
     * 首页
     */
    public function pc()
    {
        return view(config('tql.index_tql'), $this->data);
    }

    /**
     * 地区首页
     * @param Area $area
     */
    public function area(Area $area)
    {
        $this->data['area'] = $area;
        $this->data['keywords'] = miya('keyword')->derivatives($area, null, [1])->join(',');
        //加入自定义地区标题和描述
        $this->data['title'] = $area->title ?? sprintf('%s_%s分站', $this->data['title'], $area->name);
        $this->data['description'] = $area->description ?? sprintf('%s_%s分站', $this->data['description'], $area->name);

        return view(config('tql.index_tql'), $this->data);
    }

    /**
     * 移动端首页
     */
    public function mobile()
    {
        return view(config('tql.m_index_tql'), $this->data);
    }
}
